package com.fanqiechaodan.visitor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fanqiechaodan
 * @Classname Demo
 * @Description 访问者模式
 */
public class Demo {

    public static void main(String[] args) {
        List<Animal> animals = new ArrayList<>();
        animals.add(new Dog("褐色", 50));
        animals.add(new Dog("白色", 45));
        animals.add(new Cat("喵喵叫", 2));
        animals.add(new Cat("呜呜声", 3));
        animals.add(new Bird("鹦鹉", "森林"));
        animals.add(new Bird("麻雀", "田野"));

        AnimalCountVisitor animalCountVisitor = new AnimalCountVisitor();
        AnimalFeatureVisitor animalFeatureVisitor = new AnimalFeatureVisitor();

        animals.forEach(animal -> {
            animal.accept(animalCountVisitor);
            animal.accept(animalFeatureVisitor);
        });
        animalCountVisitor.printCount();
        animalFeatureVisitor.printFeatures();
    }
}
